package com.wcy.controller.perm;

import com.wcy.annotation.aop.PreAuth;
import com.wcy.entity.LearningResource;
import com.wcy.entity.Permission;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.feign.perm.FeignPermissionService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class PermissionController {
    @Resource
    private FeignPermissionService feignPermissionService;


    @GetMapping("permission/page")
    public ResponseEntity<PageData<Permission>> getPage(@RequestParam(defaultValue = "1") int pageNum,
                                                       @RequestParam(defaultValue = "10") int pageSize) {
        return ResponseEntity.ok(new PageData<>(Permission.class, Objects.requireNonNull(feignPermissionService.getPage(pageNum, pageSize).getBody()),  new ApiDescriptor("permission/add", "permission/update", "permission/delete"), ColumnConstructor.create()));
    }


    @GetMapping("permission/list")
    public ResponseEntity<List<Permission>> getList()
    {
        return feignPermissionService.getList();
    }


    @PostMapping("permission/add")
    public ResponseEntity<Void> add(@RequestBody Permission permission)
    {
        return feignPermissionService.add(permission);
    }


    @PutMapping("permission/update")
    public ResponseEntity<Void> update(@RequestBody Permission permission)
    {
        return feignPermissionService.update(permission);
    }
    @DeleteMapping("permission/delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable Integer id)
    {
        return feignPermissionService.delete(id);
    }
}
